﻿using System;
using ClrExtensions.Net.Rest;
using System.Xml.Linq;
using MediaPortal.GUI.Library;

namespace MyNetflix2
{
    public class Formats
    {
        #region enum

        public enum DiscFormat { Instant, DVD, BluRay }
        public enum SortOrder { Asc, Desc }
        #endregion

        #region locals

        private DateTime _availableFrom;
        private DateTime _availableUntil;
        private DiscFormat _format;

        #endregion

        #region Public

        public DateTime AvailableFrom
        {
            get { return _availableFrom; }
            set { _availableFrom = value; }
        }
        public DateTime AvailableUntil
        {
            get { return _availableUntil; }
            set { _availableUntil = value; }
        }
        public DiscFormat Format
        {
            get { return _format; }
            set { _format = value; }
        }

        #endregion

        /// <summary>
        /// Refresh the Disc Queue
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static XElement GetDiscFormats(string titleId, User user)
        {
            //--------------------------------------------------------------------------------
            // Set up the Rest call to get the Disc Queue
            //--------------------------------------------------------------------------------
            RestCall request = new RestCall(RestVerb.Get, titleId);

            try
            {
                //--------------------------------------------------------------------------------
                // Get the Disc Queue from Netflix
                //--------------------------------------------------------------------------------
                string xml = user.NetflixConnection.RequestResource(request, user.Token);

                //--------------------------------------------------------------------------------
                // Parse to Linq
                //--------------------------------------------------------------------------------
                XElement root = XElement.Parse(xml);

                //--------------------------------------------------------------------------------
                // Add the elements to the QueueItems class
                //--------------------------------------------------------------------------------
                return root;
            }
            catch (Exception ex)
            {
                Log.Error("My NetFlix - DVDQueue:GetDiscFormats(): Error - " + ex.Message);
                return null;
            }
        }
    }
}
